<%--
  Created by IntelliJ IDEA.
  User: TYZ
  Date: 2020/3/3
  Time: 16:14
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core"  prefix="c"%>
<!-- f标签 取得jsp一些函数工具 -->
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="f"%>
<!-- 格式化标签 -->
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>

<% String path = request.getContextPath();%>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <form id="addForm">
        出版社名:<input type="text" name="pubName"><br>
        所在国家：
        <select id="province" name="country" onchange="getCity(this)">
            <option>---请选择---</option>
        </select>
        所在所在省:
        <select id="city" name="province" onchange="getCountry(this)">
            <option>---请选择---</option>
        </select>
        所在城市:
        <select id="country" name="city">
            <option>---请选择---</option>
        </select><br>
    </form>
</body>
    <script>
        $(function(){
            getProvince();
        })
        function getProvince(){
            var html = getCitys(0);
            $("#province").html(html);
        }
        function getCity(obj){
            $("#country").html("<option value='-1'>---请选择---</option>");
            var pid = $(obj).val();
            var html = getCitys(pid);
            $("#city").html(html);
        }
        function getCountry(obj){
            var pid = $(obj).val();
            var html = getCitys(pid);
            $("#country").html(html);
        }

        function getCitys(pid){
            html ="<option value='-1'>---请选择---</option>";
            $.ajax({
                url:"/countryController/selectPro",
                type:"post",
                dataType:"json",
                data:{pid:pid},
                async:false,
                success:function(result){
                    console.log(result);
                    var citys = result;
                    $(citys).each(function(i,e){
                        /*html += "<option value="+e['id']+">"+e['pname']+"</option>";*/
                        html += "<option value='"+e['cid']+"'>"+e['cname']+"</option>";
                    })
                },
                error:function(){
                    toastr.error("系统错误，请联系管理员");
                }
            })

            return html;
        }
    </script>
</html>
